package b;

public class LoadPicture extends Thread{
    public Picture picture;

    public LoadPicture(){}

    public LoadPicture(Picture picture) {
        this.picture = picture;
    }

    @Override
    public void run() {
        System.out.println("开始准备加载图片……");
        for (int i = 0; i < 100; i++) {
            System.out.println("正在加载:" + (i + 1) + "%");
        }
        System.out.println("加载完成");
        //改变当前状态
        picture.isLoad = true;
        //唤醒显示线程
        synchronized (picture) {
            picture.notify();
        }
        //让当前线程进入休眠状态
        synchronized (picture) {
            if (!picture.isShow) {
                try {
                    picture.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }

        //下载图片
        System.out.println("开始准备下载图片...");
        for (int i = 0; i < 100; i++) {
            System.out.println("正在下载：" + (i + 1) + "%");
        }

        System.out.println("下载完成");

    }
}
